<?php
header('Content-Type:text/html;charset=utf-8'); 
session_start();
include_once( 'config.php' );
include_once( 'weibooauth.php' );
include_once ('saemysql.class.php');

$o = new SaeTOAuth( WB_AKEY , WB_SKEY , $_SESSION['keys']['oauth_token'] , $_SESSION['keys']['oauth_token_secret']  );

$last_key = $o->getAccessToken(  $_REQUEST['oauth_verifier'] ) ;

$sae = new SaeTClient(WB_AKEY, WB_SKEY, $last_key['oauth_token'], $last_key['oauth_token_secret']);
$loginUser = $sae->verify_credentials();
$loginName = $loginUser['screen_name'];
$mysql = new SaeMysql();
$sql = "select * from token where access = '".$last_key['oauth_token']."'";
$data = $mysql->getData( $sql );
if($data == false){
	$mysql->runSql("set names 'utf8'");
	$sql2 = "INSERT  INTO token ( access , asecret, name ) VALUES ( '".$last_key['oauth_token']."' , '".$last_key['oauth_token_secret']."', '".$loginName."' )";
	$mysql->runSql($sql2);
}
$mysql->closeDb();

$_SESSION['last_key'] = $last_key;
header("Location: influence.php");

?>

